
<link href="/static/admin/eleme/element.css" rel="stylesheet" />
<link href="/static/admin/eleme/element-extends.css" rel="stylesheet" />

<el-row id="add" :gutter="20" v-cloak>
  <el-col :span="24">
    <el-input v-model="dname" placeholder="请输入机构连锁店名称" class="mt mb">
      <template slot="prepend">机构名称</template>
    </el-input>

    <el-input v-model="orcode" placeholder="用于辨别连锁唯一性">
      <template slot="prepend">连锁编码</template>
    </el-input>

    <el-date-picker
      class="mt mb"
      v-model="begintime"
      type="date"
      placeholder="连锁店开始计费日期"
      style="width: 100%">
    </el-date-picker>

    <el-date-picker
      v-model="endtime"
      type="date"
      placeholder="连锁店到期截至日期"
      style="width: 100%">
    </el-date-picker>

    <el-input v-model="gnum" placeholder="下属分店最高多少家" class="mt mb">
      <template slot="prepend">分店数量</template>
    </el-input>

    <el-input v-model="user" placeholder="请输入机构联系人员姓名">
      <template slot="prepend">联系人员</template>
    </el-input>

    <el-input v-model="username" placeholder="请输入联系人手机号码，用于登录机构后台" class="mt mb">
      <template slot="prepend">登录帐号</template>
    </el-input>

  </el-col>
</el-row>

<script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/static/admin/layer/layer.js"></script>
<script type="text/javascript" src="/static/admin/js/h.js"></script>
<script type="text/javascript" src="/static/admin/eleme/vue.js"></script>
<script type="text/javascript" src="/static/admin/eleme/element.js"></script>

<script>
var vm = new Vue({
  el: '#add',
  data: {
    dname: '',
    orcode: '',
    begintime: '',
    endtime: '',
    validity: '',
    gnum: '',
    user: '',
    username: '',
  },
  methods: {
    tips: function(msg,tp){
      this.$message({
        message: msg,
        type: tp,
        showClose: true
      })
    }
  },
  mounted: function(){

  }
})
function call_submit(index){
  if (vm.dname == '') {
    vm.tips('请输入机构名称', 'warning');
    return false;
  } else if (!/^\d{5,}$/.test(vm.orcode)) {
    vm.tips('请输入5位以上机构代码，如：100010', 'warning');
    return false;
  } else if (vm.begintime == '') {
    vm.tips('请选择机构收费日期', 'warning');
    return false;
  } else if (vm.endtime == '') {
    vm.tips('请输入机构截至日期', 'warning');
    return false;
  } else if (!/^[1-9]\d*$/.test(vm.gnum)) {
    vm.tips('请输入机构下属分店最大可添加的数量', 'warning');
    return false;
  } else if (!/^[\u4e00-\u9fa5]{2,4}$/.test(vm.user)) {
    vm.tips('请输入机构联系人员姓名', 'warning');
    return false;
  } else if (!/^[1-9]\d{10}$/.test(vm.username)) {
    vm.tips('请输入联系人手机号码', 'warning');
    return false;
  }

  let data = {
    dname: vm.dname,
    orcode: vm.orcode,
    begintime: Math.round(new Date(vm.begintime).valueOf()/1000),
    endtime: Math.round(new Date(vm.endtime).valueOf()/1000),
    gnum: vm.gnum,
    user: vm.user,
    username: vm.username
  }

  console.log(data);

  H.ajax('/admin/organization/add', data, 'post', function(res){
    parent.layer.msg(res.data,{icon:1,time:2000});
    setTimeout(function(){
      parent.vm.getList();
      parent.layer.close(index);
    }, 2000)

  })
}
</script>